package com.teamF.bridge.action

import scala.collection.mutable.ArrayBuffer
//伴生类
class BridgeSensor(inParaid:String,inPara_type_code:String,inPara_value :Double) {

  var paraid : String = inParaid
  var para_type_code : String =inPara_type_code
  var para_value : Double = inPara_value
  var count : Int = 1

}
//伴生对象写入静态方法
object BridgeSensor{

  def getFinalList(scrList : ArrayBuffer[BridgeSensor]) : ArrayBuffer[BridgeSensor]={

    val finalList : ArrayBuffer[BridgeSensor] = new ArrayBuffer[BridgeSensor]()

    for(srcBs <- scrList){
      var state :Boolean  = false
      for(finalBs <- finalList){
        if(finalBs.paraid.equals(srcBs.paraid)){
          var para_value = finalBs.para_value
          para_value += srcBs.para_value
          finalBs.para_value = para_value
          finalBs.count = finalBs.count +1
          state = true
        }
      }
      if(!state){
        finalList.append(srcBs)
      }
    }
    for(finalBs <- finalList){
      finalBs.para_value = (finalBs.para_value/finalBs.count).formatted("%.4f").toDouble
    }
    //返回值
    finalList
  }
}
